<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\WxShopOrder;
use App\Admin\Actions\Grid\OrderAction;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WxShopOrderController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new WxShopOrder(['user']), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('order_id');
            $grid->column('user.user_avatar', '头像')->image('', 30, 30);
            $grid->column('user.user_name', '用户');
            $grid->column('goods_amount');
            $grid->column('discounts_amount');
            $grid->column('order_amount');
            $grid->column('payed', '支付金额');
//            $grid->column('serial_number');
            $grid->column('pay_status')->using([1 => '未付款', 2 => '已付款', 3 => '已退款'])->label([
                1 => 'primary',
                2 => 'green',
                3 => 'red'
            ]);
            $grid->column('status', '状态')->using([0 => '正常', 1 => '未发货', 2 => '已发货', 3 => '确认收货', 4 => '已退货', 5 => '取消', 6 => '用户删除'])->label([
                0 => 'blue',
                1 => 'primary',
                2 => 'red',
                3 => 'green',
                4 => 'orange2',
                5 => 'pink',
                6 => 'red',
            ]);
            $grid->column('cost_freight', '配送费');
//            $grid->column('adds_name');
//            $grid->column('adds_mobile');
//            $grid->column('address');
//            $grid->column('express');
//            $grid->column('express_no');
//            $grid->column('remark');
            $grid->column('user_remark')->limit(20);
//            $grid->column('payment_time');
//            $grid->column('ship_at');
//            $grid->column('confirm_time');
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });

            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->append((new OrderAction())->setKey($this->id));
            });
            $grid->disableCreateButton();
//            $grid->disableActions();
            // 禁用编辑按钮
            $grid->disableEditButton();
            $grid->disableDeleteButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WxShopOrder(), function (Show $show) {
            $show->field('id');
            $show->field('order_id');
            $show->field('user_id');
            $show->field('goods_amount');
            $show->field('discounts_amount');
            $show->field('order_amount');
            $show->field('payed');
            $show->field('serial_number');
            $show->field('pay_status');
            $show->field('status');
            $show->field('cost_freight');
            $show->field('adds_name');
            $show->field('adds_mobile');
            $show->field('address');
            $show->field('express');
            $show->field('express_no');
            $show->field('remark');
            $show->field('user_remark');
            $show->field('payment_time');
            $show->field('ship_at');
            $show->field('confirm_time');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WxShopOrder(), function (Form $form) {
            $form->display('id');
            $form->text('order_id');
            $form->text('user_id');
            $form->text('goods_amount');
            $form->text('discounts_amount');
            $form->text('order_amount');
            $form->text('payed');
            $form->text('serial_number');
            $form->text('pay_status');
            $form->text('status');
            $form->text('cost_freight');
            $form->text('adds_name');
            $form->text('adds_mobile');
            $form->text('address');
            $form->text('express');
            $form->text('express_no');
            $form->text('remark');
            $form->text('user_remark');
            $form->text('payment_time');
            $form->text('ship_at');
            $form->text('confirm_time');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
